import {reactive,onMounted,onUnmounted,toRefs}  from 'vue'
// vue3的组合式api 开发，更方便抽离出hooks函数
// 从功能角度，分离开发组件
function getPos(){
    let state=reactive({
      x:0,
      y:0
    })
    onMounted(()=>{
      document.onmousemove=function(e){
        state.x=e.clientX;
        state.y=e.clientY;
      }
    })
    onUnmounted(()=>{
       document.onmousemove=null;
    })

    return  {
        ...toRefs(state)
    }
}
export default getPos